// var baseUrl = "http://localhost:8081/ssm";
var baseUrl = "http://localhost:8081";
var app = getApp();

var GetRequest = function(url, data, successFuc){
  wx.request({
    url: baseUrl + url,
    data: data,
    success: function (result) {
      successFuc(result)
    }
  });
}

var PostJsonRequest = function (url, data, successFuc) {
  wx.request({
    url: baseUrl + url,
    data: data,
    header: {
      'content-type': 'application/json'
    },
    method: 'POST',
    success: function (result) {
      successFuc(result)
    }
  });
}
var payment = function(order,state){
  GetRequest("/wx/orders/updateOrderSate",{
    "orderId": order.orderId,
    "state": state
  },function(result){
    result = result.data.data
    wx.showToast({
      title: '订单已取消',
      success: function () {
        // 跳转订单详情页
        wx.navigateTo({
          url: '/order/detail/detail?objectId=' + order.orderId
        });
      }
    });
  })
}

// 导出模块
module.exports = {
	random_filename: function (tempFilePath) {
		var newDate = new Date();
		var newDateStr = newDate.toLocaleDateString();
		var extension = /\.([^.]*)$/.exec(tempFilePath);
		if (extension) {
			extension = extension[1].toLowerCase();
		}
		var name = newDateStr + "." + extension;//上传的图片的别名 
		return name;
	},
  baseUrl: baseUrl,
  GetRequest: GetRequest,
  PostJsonRequest: PostJsonRequest,
  payment: payment
}
